var Entity = function(obj, model) {
	this.copy(obj);
	
	this.class = obj.class || 'Entity';
	this.payload = obj.payload || [];
	this.model = model || [];
};

/**
 * Import all elements of an object
 * 
 * @param obj
 */
Entity.prototype.copy = function(obj) {
	var elms = Object.keys(obj);
	
	for ( var i = 0; i < elms.length; i++) {
		this[elms[i]] = obj[elms[i]];
	}
};

/**
 * Copy properties from one object to another
 * 
 * @static
 * @param from
 * @param to
 */
Entity.inherit = function(from, to) {
	var elms = Object.keys(from);
	
	for ( var i = 0; i < elms.length; i++) {
		to[elms[i]] = obj[elms[i]];
	}
};

/**
 * Recursively inflate all child objects
 */
Entity.prototype.inflate = function() {
	for ( var i = 0; i < this.payload.length; i++) {
		this.payload[i] = this.model.create(this.payload[i]);

		this.payload[i].inflate();
	}
};

module.exports = Entity;
